const { mongoose } = require('./db')

const userSchema = new mongoose.Schema({
    username: { type: String, required: true },        // 用户名
    avatar: { type: String },                          // 头像二进制数据
    createdAt: { type: Date, default: Date.now },      // 自动填充注册时间
    dengj: { type: Number, default: 0 },                // 用户等级
    collections: [                                      //书架
        {
            type: mongoose.Schema.Types.ObjectId,
            ref: 'chuangZuo',
        },
    ],
});

const chuangZuoSchema = new mongoose.Schema({
    title: { type: String, required: true },           // 标题
    content: { type: String, required: true },         // 简介
    tuavatar: { type: String },                        // 图书图片路径
    shjian: { type: Date, default: Date.now },         // 创建时间
    fabu: { type: Date },                              // 发布时间
    // redu: { type: Number, default: 0 }             // 点击量
    weiid: {                                          
        type: mongoose.Schema.Types.ObjectId,
        ref: 'userss',
        unique: false, // 将 unique 设置为 false他默认是true
    },
    
});

const zhangJie =new mongoose.Schema({
    zhangtitle: { type: String, required: true },   // 章节标题，必填
    zhengwen: { type: String, required: true }, // 章节内容，必填
    weiid: {                                           
        type: mongoose.Schema.Types.ObjectId,
        ref: 'chuangZuo',
        unique: false, // 将 unique 设置为 false他默认是true
    },
})

const userSchemaModel = mongoose.model("userss",userSchema ,"userss" )
const chuangZuoSchemaModel = mongoose.model("chuangZuo",chuangZuoSchema ,"chuangZuo" )
const zhangJieModel = mongoose.model("zhangJe",zhangJie ,"zhangJe" )

module.exports = { userSchemaModel, chuangZuoSchemaModel,zhangJieModel };